﻿using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Sasa.QualityTools.CodeAnalysis.Core.Views;
using Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Properties;
using Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.ViewModels;
using System;
using System.Runtime.InteropServices;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views
{
    [Guid("2C272FB8-D773-4459-A3E3-0D577B0AA2AF")]
    public class CodeMetricsCalculationResultWindowPane : ToolWindowPane, ICodeMetricsCalculationResultView
    {
        public object DataContext
        {
            get
            {
                return ((CodeMetricsCalculationResultContent)Content).DataContext;
            }
            set
            {
                ((CodeMetricsCalculationResultContent)Content).DataContext = value;
            }
        }


        public CodeMetricsCalculationResultWindowPane()
        {
            Caption = Resources.CodeMetricsCalculationResultWindowTitle;
            BitmapResourceID = 301;
            BitmapIndex = 0;

            var content = new CodeMetricsCalculationResultContent();
            content.DataContext = new CodeMetricsCalculationResultViewModel();
            Content = content;
        }


        public void Show()
        {
            var frame = (IVsWindowFrame)Frame;
            ErrorHandler.ThrowOnFailure(frame.Show());
        }

        public void Close()
        {
            var frame = (IVsWindowFrame)Frame;
            ErrorHandler.ThrowOnFailure(frame.Hide());
        }

        protected override void OnCreate()
        {
            var content = (CodeMetricsCalculationResultContent)Content;
            content.LoadSetting();
            base.OnCreate();
        }

        protected override void OnClose()
        {
            var content = (CodeMetricsCalculationResultContent)Content;
            content.SaveSetting();
            base.OnClose();
        }
    }
}
